<div class="ui-corner-all"><?php include "view/topmenu.php"; ?></div>
<script type="text/javascript">
	function saveRecord(x){
		_task = $('#trScope'+x).html();
		_action = $('#trAction'+x).html();
		_level = $('#selUserLevel'+x).val();
		$.post("json.php",{
			task: "saveAccessMatrix",
			scope: _task,
			action:_action,
			level:_level
		},function(data){
			if(data>0){
				alert("Record saved.");
			}
		});
	}
</script>
<div class="block">
	<table width="90%" border="1">
		<tr>
			<td><b>Scope</b></td>
			<td><b>Action</b></td>
			<td><b>Can access by</b></td>
		</tr>	
	<?php
		$i = 0;
		$accessmatrix = $_SESSION['accessmatrix'];
		while ($key_name = current($accessmatrix)) {
	?>
	<?php
			$submatrix = $key_name;
			while ($subkey_name = current($submatrix)) {
	?>
		<tr>
			<td id="trScope<?php echo $i; ?>"><?php echo key($accessmatrix); ?></td>
			<td id="trAction<?php echo $i; ?>"><?php echo key($submatrix); ?></td>
			<td>
	<?php 
		$admin = "";
		$president = "";
		$chairperson = "";
		$dean = "";
		$professor = "";
		$student = "";
		$everyone = "";
		switch( $subkey_name ){
			case 1:
				$admin = "selected='selected'";
				break;
			case 2:
				$president = "selected='selected'";
				break;
			case 3:
				$chairperson = "selected='selected'";
				break;
			case 4:
				$dean = "selected='selected'";
				break;
			case 5:
				$professor = "selected='selected'";
				break;
			case 6:
				$student = "selected='selected'";
				break;
			case 99:
				$everyone = "selected='selected'";
				break;
		} 
		
	?>
				<select id="selUserLevel<?php echo $i; ?>">
					<option value="1" <?php echo $admin; ?>>Admin</option>
					<option value="2" <?php echo $president; ?>>President</option>
					<option value="3" <?php echo $chairperson; ?>>Chairperson</option>
					<option value="4" <?php echo $dean; ?>>Dean</option>
					<option value="5" <?php echo $professor; ?>>Professor</option>
					<option value="6" <?php echo $student; ?>>Student</option>
					<option value="99" <?php echo $everyone; ?>>Everyone</option>
				</select>
				and content owner.
				<input type="button" value="Save" onclick="saveRecord(<?php echo $i; ?>)" />
			</td>			
		</tr>
	<?php
				$i++;
				next($submatrix);
			}
	?>
	<?php
		    next($accessmatrix);
		}
	?>
	</table>
</div>

